package com.ala4.oxcafe.controller;

import com.ala4.oxcafe.boot.ExcelExport;
import com.ala4.oxcafe.boot.annotation.Permission;
import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.boot.page.PageResult;
import com.ala4.oxcafe.domain.R;
import com.ala4.oxcafe.entity.WarrantyOrder;
import com.ala4.oxcafe.service.WarrantyOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 质保单
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 17:34
 */
@Slf4j
@RestController
@RequestMapping("/warranty-order")
@AllArgsConstructor
@Tag(name = "质保单管理", description = "用于管理质保单")
public class WarrantyOrderController {

    private final WarrantyOrderService warrantyOrderService;

    @Operation(summary = "分页查询质保单")
    @GetMapping("/page")
    public R<PageResult<WarrantyOrder>> page(PageDomain pageDomain, WarrantyOrder warrantyOrder) {
        return R.ok(PageResult.iPage(warrantyOrderService.warrantyOrderPage(pageDomain, warrantyOrder)));
    }

    @Operation(summary = "导出质保单")
    @GetMapping("/export")
    @ExcelExport(value = WarrantyOrder.class)
    public R<PageResult<WarrantyOrder>> export(PageDomain pageDomain, WarrantyOrder warrantyOrder) {
        return R.ok(PageResult.iPage(warrantyOrderService.warrantyOrderPage(pageDomain, warrantyOrder)));
    }

    @Operation(summary = "质保单详情")
    @GetMapping("/{warrantyId}")
    public R<WarrantyOrder> info(@PathVariable Long warrantyId) {
        return R.ok(warrantyOrderService.warrantyOrderInfo(warrantyId));
    }

    @Operation(summary = "微信用户查询自己的质保单")
    @GetMapping("/user-all")
    public R<List<WarrantyOrder>> userAll() {
        return R.ok(warrantyOrderService.weChatUserAll());
    }


    @Operation(summary = "根据手机号查询质保单-公开接口")
    @GetMapping("/public/{phone}")
    @Permission(permissionPublic = true)
    public R<List<WarrantyOrder>> publicWarranty(@PathVariable String phone) {
        return R.ok(warrantyOrderService.publicWarrantyUserPhone(phone));
    }


}
